package com.ita.activemq;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.command.ActiveMQQueue;

import com.ita.factory.MQConnFactory;

/**
 * Hello world!
 * 
 */
public class ProducerManager implements JMSSender {

	private static final String SEND_QUENE_NAME = "M2A_QUEUE";
	private static Destination queue;
	private static Session session;
	private MessageProducer producer;

	public ProducerManager() throws JMSException {
		queue = new ActiveMQQueue(SEND_QUENE_NAME);
		session = MQConnFactory.getConnection().createSession(true,
				Session.AUTO_ACKNOWLEDGE);
		producer = session.createProducer(queue);
	}

	/***
	 * send info to queue, here is regist info
	 */
	@Override
	public void send(String json) {

		TextMessage msg;
		try {
			msg = session.createTextMessage(json);
			
			producer.send(msg);
//			producer.close();
			
			session.commit();
//			session.close();
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
